﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentData;
using Huazhu.PMS.Framework.Data;

namespace Huazhu.PMS.Framework.Core
{
    internal class OrgInfoDataAccess : BaseDataAccess
    {
        internal List<OrgInfo> GetOrgInfo(string parameterTypeID)
        {
            var sql = "SELECT [dbo].[Org_Info].[sOrgID], [dbo].[Org_Info].[sOrgName], [dbo].[Org_Info].[sParentOrgID], [Org_Info].[sHotelBiz], [dbo].[Org_Info].[sHotelProperty],"
                        + " [dbo].[Org_Info].[sAreaID], [dbo].[Org_Info].[sHotelLevel], [dbo].[Parameter_Info].[sScript],"
                        + " [dbo].[Org_Info].[sAddress], [dbo].[Org_Info].[sTel], [dbo].[Org_Info].[sFax], [dbo].[Org_Info].[sZip]"
                        + " FROM [dbo].[Org_Info] INNER JOIN"
                        + " [dbo].[Parameter_Info] ON [dbo].[Parameter_Info].[sParameterID]=[dbo].[Org_Info].[sOrgTypeID]"
                        + " AND [dbo].[Parameter_Info].[sParameterTypeID]=@PARAM_TYPE_ID WHERE [dbo].[Org_Info].[bIsDel]=0";

            using (var context = DataHelper.GetBaseDbContext())
            {
                var orgInfos =
                    context.Sql(sql).Parameter("PARAM_TYPE_ID", parameterTypeID).QueryMany<OrgInfo>(delegate(OrgInfo map, IDataReader reader)
                    {
                        map.OrgID = reader.GetString("sOrgID");
                        map.OrgName = reader.GetString("sOrgName");
                        map.ParentOrgID = reader.GetString("sParentOrgID");

                        map.HotelBiz = reader.GetString("sHotelBiz");
                        map.HotelProperty = reader.GetString("sHotelProperty");
                        map.AreaID = reader.GetString("sAreaID");

                        map.HotelLevel = reader.GetString("sHotelLevel");
                        map.Script = reader.GetString("sScript");
                        map.Address = reader.GetString("sAddress");

                        map.Tel = reader.GetString("sTel");
                        map.Fax = reader.GetString("sFax");
                        map.Zip = reader.GetString("sZip");
                        //TODO:更多字段
                    });
                return orgInfos;
            }
        }
    }
}
